import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import VueLazyLoad from "vue-lazyload";
import Message from "vue-m-message";
import 'vue-m-message/dist/index.css';
Vue.config.productionTip = false

import PageView from "@/components/PageView.vue";
import PageHeader from "@/components/PageHeader.vue";
import IndexSwiper from "@/components/IndexSwiper.vue";
Vue.component("page-view",PageView);
Vue.component("page-header",PageHeader);
Vue.component("index-swiper",IndexSwiper);

import API from "./utils/API";
Vue.prototype.$api = API;

// 全局混合
Vue.mixin({
  data(){
    return{
      baseURL:"https://www.softeem.xin/myxj/"
    }
  }
});

import LoadingImg from "./assets/img/loading.gif";
import ErrorImg from "./assets/img/error.jpg";
// 懒加载
Vue.use(VueLazyLoad, {
  // 预加载的页面大小
  preLoad: 1,
  error: ErrorImg,
  loading: LoadingImg,
  // 加载尝试次数
  attempt: 2
});

// 加载提示
Vue.use(Message,{name:"msg"});

// 表单验证
import Vuerify from 'vuerify';
Vue.use(Vuerify)

// 左滑删除
import swipeCell from 'vue-swipe-cell';
Vue.use(swipeCell);

// 导入animate.css
import "animate.css";

// 全局自定义命令
Vue.directive("longpress",{
  // bind一次绑定，
  // inserted被绑定元素插入父节点时调用 (仅保证父节点存在，但不一定已被插入文档中)
  // inserted在绑定的时候，如果当前元素被v-if又被keep-alive，就会被多次绑定二级事件，
  // 所以就会造成事件多次的执行
  bind(el,binding,vnode,oldV){
    // el当前绑定的元素
    // binding一个对象，当中 value：指令的绑定值，name：指令名(longpress)
    //                      arg：传的参数 v-longpress:[200],arg指的就是200
    // vnode：虚拟节点，当中context值得是当前的new出来的Vue
    let timeout = binding.arg || 500;
    let timeId = null;
    el.addEventListener("touchstart",event=>{
      timeId =  setTimeout(() => {
        binding.value.call(vnode.context,event);
      }, timeout);
    });
    el.addEventListener("touchmove",event=>{
      clearTimeout(timeId);
    });
    el.addEventListener("touchcancel",event=>{
      clearTimeout(timeId);
    });
    el.addEventListener("touchend",event=>{
      clearTimeout(timeId);
    });
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
